/*
 * Copyright (c) 2001, 2002 Boris Pruessmann and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Common Public License v0.5
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors:
 *    Boris Pruessmann - Initial implementation.
 */
package net.sourceforge.perforce.api.internal;

/**
  * Wrapper class for Perforce API Spec class.
  * 
  * @version $Revision: 252 $
  * @author  <a href="mailto:bpruessmann@users.sourceforge.net>Boris Pruessmann</a>
  */
public final class Spec
{
	// --------------------------------------------------------------------------- Private Variables
	
	/** Used to store the native reference.
	  * <br>DON'T TOUCH THE CONTENT OF THIS VARIABLE 
	  */
	private int _nativeHandle;

	// ------------------------------------------------------------------------- Public Constructors

	/** Constructor for Spec. */
	public Spec()
	{
		construct();
	}
	
	// ------------------------------------------------------------------------------ Public Methods
	
	/** @see Object#finalize() */
	public void finalize() 
		throws Throwable
	{
		// TODO: Manually destruct
		super.finalize();
		destruct();
	}

	/** Wrapper for Spec::Decode. 
	  * decode a spec definition from a string.
	  * 
	  * @param specDefString string to decode.
	  * @param error error object to be used in case of an error.
	  */
	public native void decode(String specDefString, Error error);

	/** Wrapper for Spec::Format. 
	  * turn SpecData into a spec string.
	  * 
	  * @param data SpecData to format.
	  * @return the formatted SpecData.
	  */
	public native String format(SpecData data);
	
	/** Wrapper for Spec::Parse. 
	  * parse a spec string into SpecData.
	  * 
	  * @param specString specification to use.
	  * @param data SpecData that will contain the parsed specString.
	  * @param error error object to be used in case of an error.
	  * @param valid 1 if specStrig should be validated.
	  */
	public native void parse(String specString, SpecData data, 
		Error error, int valid);

	// ----------------------------------------------------------------------------- Private Methods

	/** Called by the constructor to initialize the native side
	  * of this class.
	  */
	private native void construct();
	
	/** Called by finalize() to destroy the native side of this
	  * class.
	  */
	private native void destruct();
}
